package io.bdmc.common.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 常量
 * 
 * @author huang lu
 * @email hlkyo@qq.com
 * @date 2016年11月15日 下午1:23:52
 */
@Component
public class Constant {
    /** 超级管理员ID */
    public static final int SUPER_ADMIN = 1;

    public static String APPID;// 微信appid

    public static String MSGURL;

    public static String APPSECRET;// 微信appsecret

    public static String EXPORTPATH;// 导出路径文件夹

    public static int INTERVAL;

    public static int EXPIREMIN;

    public static int SHORTMSGAPPID;// 短信平台appid

    public static String SHORTMSGAPPKEY;// 短信平台key

    public static String TEMPLATEID1;// 报警模板消息

    public static String MailUserName;// 邮箱用户名

    public static String MailPwd;// 邮箱密码

    public static String MailHost;// 邮箱smtp.exmail.qq.com

    public static String ShortMsgSign;// 短信签名

    public static String nbiotDomain;// 移动接口地址

    public static String nbiotApiKey;// 移动接口密钥

    @Value("${wechat.appid}")
    public void setAppid(String appid) {
        APPID = appid;
    }

    @Value("${wechat.appsecret}")
    public void setAppsecret(String appsecret) {
        APPSECRET = appsecret;
    }

    @Value("${wechat.validate.Interval}")
    public void setInterval(int interval) {
        INTERVAL = interval;
    }

    @Value("${wechat.validate.expiredMin}")
    public void setExpiredMin(int expiredMin) {
        EXPIREMIN = expiredMin;
    }

    @Value("${shortMsg.appid}")
    public void setShortMsgAppid(int shortmsgAppid) {
        SHORTMSGAPPID = shortmsgAppid;
    }

    @Value("${shortMsg.appkey}")
    public void setShortMsgAppkey(String shortmsgAppkey) {
        SHORTMSGAPPKEY = shortmsgAppkey;
    }

    @Value("${shortMsg.sign}")
    public void setShortMsgSign(String shortMsgSign) {
        ShortMsgSign = shortMsgSign;
    }

    @Value("${wechat.exportPath}")
    public void setExportPath(String exportPath) {
        EXPORTPATH = exportPath;
    }

    @Value("${wechat.msgUrl}")
    public void setMsgUrl(String url) {
        MSGURL = url;
    }

    @Value("${wechat.templateId1}")
    public void setTemplateId1(String tpid) {
        TEMPLATEID1 = tpid;
    }

    @Value("${spring.mail.username}")
    public void setMailUserName(String username) {
        MailUserName = username;
    }

    @Value("${spring.mail.password}")
    public void setMailPwd(String pwd) {
        MailPwd = pwd;
    }

    @Value("${spring.mail.host}")
    public void setMailHost(String mailHost) {
        MailHost = mailHost;
    }

    @Value("${nbiot.domainName}")
    public void setNbiotDomain(String domainName) {
        nbiotDomain = domainName;
    }

    @Value("${nbiot.apiKey}")
    public void setNbiotApiKey(String apiKey) {
        nbiotApiKey = apiKey;
    }

    /**
     * 菜单类型
     * 
     * @author huang lu
     * @email hlkyo@qq.com
     * @date 2016年11月15日 下午1:24:29
     */
    public enum MenuType {
        /**
         * 目录
         */
        CATALOG(0),
        /**
         * 菜单
         */
        MENU(1),
        /**
         * 按钮
         */
        BUTTON(2);

        private int value;

        private MenuType(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    /**
     * 定时任务状态
     * 
     * @author huang lu
     * @email hlkyo@qq.com
     * @date 2016年12月3日 上午12:07:22
     */
    public enum ScheduleStatus {
        /**
         * 正常
         */
        NORMAL(0),
        /**
         * 暂停
         */
        PAUSE(1);

        private int value;

        private ScheduleStatus(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    /**
     * 云服务商
     */
    public enum CloudService {
        /**
         * 七牛云
         */
        QINIU(1),
        /**
         * 阿里云
         */
        ALIYUN(2),
        /**
         * 腾讯云
         */
        QCLOUD(3);

        private int value;

        private CloudService(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    // public static int getSmsTemplateid(String rawData) {
    // int tp_id = 0;
    // if (rawData.indexOf("020100") != -1) {// 火警
    // tp_id = 265407;
    // } else if (rawData.indexOf("020200") != -1 || rawData.indexOf("020300") !=
    // -1) {// 故障
    // tp_id = 269186;
    // } else if (rawData.indexOf("020400") != -1 || rawData.indexOf("020700") !=
    // -1) {// 清除火警
    // tp_id = 268979;
    // } else if (rawData.indexOf("0099") != -1) {// 离线
    // tp_id = 268981;
    // } else if (rawData.indexOf("020A00") != -1) {// 拆除
    // tp_id = 268983;
    // }

    // return tp_id;
    // }

    public static int getSmsTemplateidByStreamId(String streamId, String type) {
        int tp_id = 0;
        if (type.equals("alarm")) {
            if (streamId.equals("fireAlarm")) {
                tp_id = 265407;
            } else if (streamId.equals("power")) {
                tp_id = 269186;
            } else if (streamId.equals("sensor")) {
                tp_id = 269186;
            } else if (streamId.equals("online")) {
                tp_id = 268981;
            } else if (streamId.equals("integral")) {
                tp_id = 268983;
            }
        } else if (type.equals("clean") && streamId.equals("fireAlarm")) {
            tp_id = 268979;
        }
        return tp_id;
    }

    public static int getAlarmTypeByStreamId(String streamId, String type) {
        int tp = 0;
        if (type.equals("alarm")) {
            if (streamId.equals("fireAlarm")) {
                tp = 2;// 火警
            } else if (streamId.equals("power")) {
                tp = 5;// 低电压
            } else if (streamId.equals("sensor")) {
                tp = 3;// 传感器故障
            } else if (streamId.equals("online")) {
                tp = 1;// 离线
            } else if (streamId.equals("integral")) {
                tp = 4;// 拆除
            }
        }
        return tp;
    }

    public static String getTemplateDetailByStreamId(String streamId, String type) {
        String tp_id = "";

        if (type.equals("alarm")) {
            if (streamId.equals("fireAlarm")) {
                tp_id = "尊敬的%s用户，您位于%s的%s发生火灾告警，请尽快确认情况,及时处理!";
            } else if (streamId.equals("power")) {
                tp_id = "尊敬的%s用户，您位于%s的%s处于%s状态，请及时检查并处理！";
            } else if (streamId.equals("sensor")) {
                tp_id = "尊敬的%s用户，您位于%s的%s处于%s状态，请及时检查并处理！";
            } else if (streamId.equals("online")) {
                tp_id = "尊敬的%s用户，您位于%s的%s处于离线状态，请及时检查并处理！";
            } else if (streamId.equals("integral")) {
                tp_id = "尊敬的%s用户，您位于%s的%s发生拆除告警,请及时检查并处理!";
            }
        } else if (type.equals("clean") && streamId.equals("fireAlarm")) {
            tp_id = "尊敬的%s用户，您位于%s的%s已解除火灾告警！";
        }
        return tp_id;
    }

    public static int getVoiceTemplateidByStreamId(String streamId, String type) {
        int tp_id = 0;

        if (type.equals("alarm")) {
            if (streamId.equals("fireAlarm")) {
                tp_id = 265409;
            } else if (streamId.equals("power")) {
                tp_id = 269187;
            } else if (streamId.equals("sensor")) {
                tp_id = 269187;
            } else if (streamId.equals("online")) {
                tp_id = 268987;
            } else if (streamId.equals("integral")) {
                tp_id = 268988;
            }
        } else if (type.equals("clean") && streamId.equals("fireAlarm")) {
            tp_id = 268984;
        }
        return tp_id;
    }

    public static String getStrByStreamId(String streamId, String type) {
        String str = "";
        switch (streamId) {
        case "heartbeat":
            str = "心跳";
            break;
        case "online":
            if (type.equals("clean")) {
                str = "心跳";
            } else {
                str = "离线";
            }
            break;
        case "self_check":
            str = "自检";
            break;
        case "batteryPower":
            str = "电池电量";
            break;
        case "signalStrength":
            str = "信号强度(dBm)";
            break;
        case "signalSNR":
            str = "信噪比(dB)";
            break;
        case "signalECL":
            str = "信号覆盖等级(dB)";
            break;
        case "rssi":
            str = "RSSI场强值";
            break;
        case "dirtyPercent":
            str = "污染百分比";
            break;
        case "smokeScope":
            str = "烟雾浓度";
            break;
        case "msg":
            if (type.equals("reset")) {
                str = "复位";
            }
            break;
        default:
            break;
        }
        return str;
    }

    public static String formateShopPlace(Integer place) {
        String str = "";
        switch (place) {
        case 1:
            str = "学校";
            break;
        case 2:
            str = "医院/诊所";
            break;
        case 3:
            str = "商店/超市";
            break;
        case 4:
            str = "餐饮场所";
            break;
        case 5:
            str = "宾馆/旅馆";
            break;
        case 6:
            str = "娱乐/休闲场所";
            break;
        case 7:
            str = "网吧";
            break;
        case 8:
            str = "美容/美发/洗浴场所";
            break;
        case 9:
            str = "生产/加工企业";
            break;
        case 10:
            str = "其他";
            break;
        case 11:
            str = "消防栓";
            break;
        case 12:
            str = "微形消防站";
            break;
        case 13:
            str = "医疗服务站";
            break;
        case 14:
            str = "消防支队";
            break;
        default:
            break;
        }
        return str;
    }

    public static Integer getShopPlaceFromStr(String place) {
        Integer str = 0;
        switch (place) {
        case "学校":
            str = 1;
            break;
        case "医院/诊所":
            str = 2;
            break;
        case "商店/超市":
            str = 3;
            break;
        case "餐饮场所":
            str = 4;
            break;
        case "宾馆/旅馆":
            str = 5;
            break;
        case "娱乐/休闲场所":
            str = 6;
            break;
        case "网吧":
            str = 7;
            break;
        case "美容/美发/洗浴场所":
            str = 8;
            break;
        case "生产/加工企业":
            str = 9;
            break;
        case "其他":
            str = 10;
            break;
        case "消防栓":
            str = 11;
            break;
        case "微形消防站":
            str = 12;
            break;
        case "医疗服务站":
            str = 13;
            break;
        case "消防支队":
            str = 14;
            break;
        default:
            break;
        }
        return str;
    }

    public static String formAlarmType(Integer alarmType) {
        String typeStr = "";
        switch (alarmType) {
        case 1:
            typeStr = "离线";
            break;
        case 2:
            typeStr = "火警";
            break;
        case 3:
            typeStr = "传感器故障";
            break;
        case 4:
            typeStr = "拆除报警";
            break;
        case 5:
            typeStr = "低压报警";
            break;
        default:
            break;
        }
        return typeStr;
    }
    // 火警原因，明火走火，漏电，自燃，人为纵火，易燃易爆物品燃爆，用电负荷超载，雷击，生活用火不慎，生产作业不慎

    public static String formAlarmReason(Integer dealType) {
        String typeStr = "";
        switch (dealType) {
        case 1:
            typeStr = "明火走火";
            break;
        case 2:
            typeStr = "漏电";
            break;
        case 3:
            typeStr = "自燃";
            break;
        case 4:
            typeStr = "人为纵火";
            break;
        case 5:
            typeStr = "易燃易爆物品燃爆";
            break;
        case 6:
            typeStr = "用电负荷超载";
            break;
        case 7:
            typeStr = "雷击";
            break;
        case 8:
            typeStr = "生活用火不慎";
            break;
        case 9:
            typeStr = "生产作业不慎";
            break;
        default:
            break;
        }
        return typeStr;
    }

    // 1真实火警，2误报，3故障，4测试
    public static String formDealType(Integer dealType) {
        String typeStr = "";
        switch (dealType) {
        case 1:
            typeStr = "真实火警";
            break;
        case 2:
            typeStr = "误报";
            break;
        case 3:
            typeStr = "故障";
            break;
        case 4:
            typeStr = "测试";
            break;
        case 5:
            typeStr = "离线";
            break;
        case 6:
            typeStr = "传感器故障";
            break;
        case 7:
            typeStr = "拆除告警";
            break;
        case 8:
            typeStr = "低压告警";
            break;
        default:
            break;
        }
        return typeStr;
    }

    // 1电话确认，2视频确认，3app图片确认，4自动确认，5其他方式
    public static String formAlarmMethod(Integer alarmMethod) {
        String typeStr = "";
        switch (alarmMethod) {
        case 1:
            typeStr = "电话确认";
            break;
        case 2:
            typeStr = "视频确认";
            break;
        case 3:
            typeStr = "app图片确认";
            break;
        case 4:
            typeStr = "自动确认";
            break;
        case 5:
            typeStr = "其他方式";
            break;
        case 6:
            typeStr = "现场确认";
            break;
        default:
            break;
        }
        return typeStr;
    }

}
